package chixing.day16.class23;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class ReaderDemo {
    public static void main(String[] args) {
     //1创建字符读取流
        Reader r = null;
        try {
            r= new FileReader("D:\\a\\a.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        //2.读取数据(一个字符一个字符读取)
      char[] chars = new char[1024];
        int temp;
        int i = 0;
        try{
        while((temp = r.read())!= -1)
            chars[i++] =(char) temp;
    }catch (IOException e) {
        throw new RuntimeException(e);
    }finally{
            if(r != null){
                try {
                    r.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        String result = new String(chars, 0, i);
        System.out.println(result);
}
}
